package com.wxpay.sdk;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;



public class WXConfig extends WXPayConfig{

	private byte[] certData;
    private static WXConfig INSTANCE;

    private WXConfig() throws Exception{
    		ClassLoader classLoader = getClass().getClassLoader();
    		URL url = classLoader.getResource("apiclient_cert.p12");
        File file = new File(url.getFile());
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

    public static WXConfig getInstance() throws Exception{
        if (INSTANCE == null) {
            synchronized (WXConfig.class) {
                if (INSTANCE == null) {
                    INSTANCE = new WXConfig();
                }
            }
        }
        return INSTANCE;
    }
    /**
     * 公众账号ID 微信支付分配的公众账号ID（企业号corpid即为此appId）
     */
    public String getAppID() {
        return "wxbf18b4c1f2df18bf";
    }
    /**
     * 商户号 微信支付分配的商户号
     */
    public String getMchID() {
        return "1371489502";
    }
    /**
     * 微信商户平台(pay.weixin.qq.com)-->账户设置-->API安全-->密钥设置
     */
    public String getKey() {
        return "15913321009133755773081580074941";
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis;
        certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }


    public int getHttpConnectTimeoutMs() {
        return 2000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    IWXPayDomain getWXPayDomain() {
        return WXPayDomainSimpleImpl.instance();
    }

    public String getPrimaryDomain() {
        return "api.mch.weixin.qq.com";
    }

    public String getAlternateDomain() {
        return "api2.mch.weixin.qq.com";
    }

    @Override
    public int getReportWorkerNum() {
        return 1;
    }

    @Override
    public int getReportBatchSize() {
        return 2;
    }
}